package code.rocky.chapter05;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Suggest60 {
    public static void main(String[] args) {
//        int[] arr = new int[]{1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200};
        int[] arr = new int[]{
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
                1, 34, 1000, 1230, 213, 12321, 167, 178, 90, 100, 199, 200,
        };
        List<Integer> list = Arrays.stream(arr).boxed().collect(Collectors.toList());
        System.out.println(sum(arr));
        System.out.println(sum(list));

    }

    public static int sum(int[] dates) {
        long startTime = System.nanoTime();
        int sum = 0;
        for (int i = 0; i < dates.length; i++) {
            sum += dates[i];
        }
        System.out.println("int[] cost time : " + (System.nanoTime() - startTime) + " ms");
        return sum;
    }

    public static int sum(List<Integer> dates) {
        long startTime = System.nanoTime();
        int sum = 0;
        for (int i = 0; i < dates.size(); i++) {
            // 拆箱操作,Integer对象通过拆箱转换成了一个int基本类型
            sum += dates.get(i);
        }
        System.out.println("List<Integer> cost time: " + (System.nanoTime() - startTime) + " ms");
        return sum;
    }
}
